<include file="header"/>
<div class="wraper clearfix">
    <div class="banner">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <volist name="data['img']" id="vo">
                    <div class="swiper-slide"><a href="#"><img src="{BEESCRM:$vo.image}"/></a></div>
                </volist>
            </div>

            <div class="swiper-pagination"></div>
        </div>
    </div>
    <a href="javascript:history.go(-1)" class="back">
    	<span class="iconfont icon-iconfontcolor90"></span> 返回上一页
    </a>
    <div class="product-detail-info">
        <div class="clearfix">
            <p class="product-name pull-left" style="width:99%;border-right:none;">
                {BEESCRM:$data['goods_name']}
            </p>
            <p class="text-12">
                <if condition="$data['picked'] eq 1">
                    <span class="product-label text-12">自提</span>
                    <else/>
                    <span class="product-label text-12">快递</span>
                </if>
                <if condition="$data['other'] eq 1">
                    <span class="product-label text-12">厂家直营</span>
                </if>
                <span class="sale pull-right">商家：
                    <if condition="$data['name'] eq null ">
                        超级管理员
                    <else/>
                        {BEESCRM:$data['name']}
                    </if>
                </span>
            </p>
        </div>
        <div class="prize">
            <p class="new-prize">￥{BEESCRM:$data['goods_price']}</p>
            <p>
                <span class="old-prize" style="text-decoration:line-through;">￥{BEESCRM:$data['goods_original_price']}</span>
                <span class="sale pull-right">已售{BEESCRM:$data['sale_num']}</span>
            </p>
        </div>
    </div>
    <input type="hidden" id="goods_id" value="{BEESCRM:$data['goods_id']}">
    <div class="tab-box">
        <ul class="tab clearfix">
            <li class="tab-list active">图文详情</li>
            <li class="tab-list">用户评价</li>
            <li class="tab-list">猜你喜欢</li>
        </ul>
        <div class="container clearfix actived">
            {BEESCRM:$data['content']}
        </div>
        <div class="container comment">
        	<if condition="$data['comment']">
	        	<volist name="data['comment']" id="vo">
                    <if condition="$vo['cut_picture'] eq 0">
		            <div class="comment-list">
		                <div class="comment-info">
		                    <div class="user-photo"><img src="{BEESCRM:$vo.avatar|default='/assets/repairnew/images/headimg.jpg'}"/></div>
		                    <p class="user-name">{BEESCRM:$vo['real_name']|default="匿名用户"}</p>
		                    <div class="start">
		                    	<for start="0" end="$vo['goods_star']">
		                            <span class="iconfont icon-3"></span>
		                        </for>
		                    </div>
		                </div>
		                <p class="comment-text">{BEESCRM:$vo['goods_comment']}</p>
                        <div class="comment_img clearfix">
                            <div class="img-list"><img src="{BEESCRM:$vo.comment_picture}"></div>
                        </div>
		                <p class="time"><if condition="$vo['goods_comment_time'] neq 0">{BEESCRM:$vo['goods_comment_time']|date="Y-m-d H:i:s",###}</if></p>
                        <if condition="$vo.reply_content neq ''">
                        <p>商家回复：{BEESCRM:$vo.reply_content}</p>
                        </if>
		            </div>
                    </if>
	            </volist>
	       <else/>
	       		<p></p>
	            <div class="comment-list">
		            <div class="comment-info">
		            	<p>暂无评论</p>
		            	<p></p>
		        	</div>
		        </div>
		        <p></p>
	        </if>
        </div>
        <div class="container clearfix">
        	<volist name="data['like']" id="vo">
            <a href="{BEESCRM::U('base/store/goodsDetail',array('goods_id'=>$vo['goods_id'],'did'=>$did,'origin'=>$origin,'store_id'=>$storeId))}" class="tabulation half clearfix">
	            <div class="tabulation-img"><img src="{BEESCRM:$vo['goods_thumb']}"/></div>
	            <div class="tabulation-info">
	                <p class="tabulation-name">{BEESCRM:$vo['goods_name']|mb_substr=0,10,'utf8'}</p>
	                <p class="prize"><span class="new-prize">￥{BEESCRM:$vo['goods_price']}</span><s class="old-prize">￥{BEESCRM:$vo['goods_original_price']}</s>
                    <p><span class="sale" style="margin-left: 0;">已售{BEESCRM:$vo['sale_num']}</span></p>
	            </div>
	        </a>
            </volist>
        </div>
    </div>
</div>
<div class="picture">
</div>
<div class="detail-menu">
    <a href="{BEESCRM::U('base/store/index',array('store_id'=>$storeId,'origin'=>$origin))}" class="white-btn"><span class="iconfont icon-unie623"></span><p>店铺</p></a>
    <a href="javascript:void(0)" class="white-btn <if condition="$data['collection'] eq 1">collect</if>" id='addToCollection'><span class="iconfont icon-shoucang"></span><p>收藏</p></a>
    <a href="{BEESCRM::U('base/store/cart',array('store_id'=>$storeId,'origin'=>$origin))}" class="white-btn"><span class="iconfont icon-gouwu"></span><p>购物车</p><span class="circle"></span></a>
    <a href="javascript:void(0)" class="shopping-car" data-type="cart">加入购物车</a>
    <a href="javascript:void(0)" class="buy" data-type="buy">立即购买</a>
</div>
<a href="#" class="back-to-top"><span class="iconfont icon-fanhuidingbu"></span><p>顶部</p></a>
<div class="pop-box" id="cover"></div>
<div class="pop" id="shopping">
    <div class="pop-product-info">
        <div class="product-img"><img src="{BEESCRM:$data.goods_thumb}"></div>
        <div class="product-text">
            <p>{BEESCRM:$data['goods_name']}</p>
            <p class="new-prize" id="single-price">￥{BEESCRM:$data['goods_price']}</p>
        </div>
        <span class="iconfont icon-guanbi close"></span>
    </div>
    <div style="height: 240px;overflow: auto">
        <volist name="array" id="vo">
            <p class="classify spec_name">{BEESCRM:$vo['spec_name']}</p>
            <p class="norms clearfix goods_spec">
                <volist name="vo['list']" id="v">
                    <span class="norms-list" data-name="{BEESCRM:$vo['spec_name']}" data-value="{BEESCRM:$v}">{BEESCRM:$v}</span>
                </volist>
            </p>
        </volist>
        <input type="hidden" id="picked" value="{BEESCRM:$data.picked}">
        <if condition="$data.picked eq 1">
            <p class="classify">提取地点</p>
            <p class="norms clearfix" id="since_address">
                <volist name="address" id="vo">
                    <span class="norms-list half" data-value="{BEESCRM:$vo.since_id}">{BEESCRM:$vo.since_address}</span>
                </volist>
            </p>
        </if>
        <p class="classify">数量</p>
        <div class="classify-box clearfix">
            <div class="quantity pull-left">
                <span class="iconfont icon-iconfont55" data-status="sub"></span>
                <input type="number" value="1" id="buy-num" data-status="input" autocomplete="on">
                <span class="iconfont icon-jia" data-status="plus"></span>
            </div>
            <span class="stock pull-left" id="product-stock">库存：{BEESCRM:$data['stock']}件</span>
            <input type="hidden" id="stock" value="{BEESCRM:$data['stock']}">
        </div>
    </div>
    <input type="hidden" id="buy_type" value="">
    <input type="hidden" id="goods_spec_id" value="0">
    <a href="#" class="confirm" data-id="{BEESCRM:$data['goods_id']}">确认</a>
</div>
<include file="commonJs" />
<include file="footer"/>
<style type="text/css">
    .scrm-loadding1 {
        display: none;
        position: fixed;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.2);
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
    }
    .scrm-loadding1 img{
        position: fixed;
        left: 20%;
        top: 20%;
    }
</style>
<script type="text/javascript">
    $(function(){
        var width = $(window).width();
        $('.banner').css('height',width);

        var swiper = new Swiper('.banner .swiper-container', {
            pagination: '.banner .swiper-pagination',
            paginationClickable: true,
            centeredSlides: true,
            autoplay: 2500,
            autoplayDisableOnInteraction: false,
            loop: true
        });

        $('.quantity').changeAmount();
    });
    
    $('.tab').on('click','li',function(){
        var idx = $(this).index();
        $(this).addClass('active').siblings().removeClass('active');
        $('.container').eq(idx).addClass('actived').siblings().removeClass('actived');
    });
    $('.shopping-car').click(function(){
        $('#cover').show();
        $('#shopping').addClass('up');
        $('#buy_type').val($(this).data('type'));
    });
    $('.buy').click(function(){
        $('#cover').show();
        $('#shopping').addClass('up');
        $('#buy_type').val($(this).data('type'));
    });
    $('.close').click(function(){
        $('#shopping').removeClass('up');
        $('#cover').fadeOut(500);
    });
    $('.norms .norms-list').click(function(){
        $(this).addClass('checked').siblings().removeClass('checked');
    });
    $('#shopping .goods_spec').click(function(){
        var num = $('#shopping .spec_name').length;
        var check_num = $('#shopping .goods_spec .checked').length;
        if (num == check_num) {
            var i = 0;
            var a = b = c = '';
            $('#shopping .goods_spec .checked').each(function () {
                if (!a) {
                    a = $(this).data('value');
                    i = 1;
                } else if (!b) {
                    b = $(this).data('value');
                    i = 2;
                } else if (!c) {
                    c = $(this).data('value');
                    i = 3;
                }
            });

            var goods = '{BEESCRM:$goods}';
            var obj = JSON.parse(goods);
            var goods_spec_id, price, stock;
            if (i == 3) {
                goods_spec_id = obj[a][b][c]['goods_spec_id'];
                price = obj[a][b][c]['price'];
                stock = obj[a][b][c]['stock'];
            } else if (i == 2) {
                goods_spec_id = obj[a][b]['goods_spec_id'];
                price = obj[a][b]['price'];
                stock = obj[a][b]['stock'];
            } else if (i == 1) {
                goods_spec_id = obj[a]['goods_spec_id'];
                price = obj[a]['price'];
                stock = obj[a]['stock'];
            }

            $('#single-price').text('￥' + price);
            if(!stock) {
                $('#product-stock').text('暂无库存');
                $('#stock').val('0');
            } else {
                $('#product-stock').text('库存：'+ stock +'件');
                $('#stock').val(stock);
            }
            $('#goods_spec_id').val(goods_spec_id);
        }
    });

    $('.confirm').click(function(){
        var num = $('#shopping .spec_name').length;
        var check_num = $('#shopping .goods_spec .checked').length;
        if(num != check_num) {
            $.alert('error','请选择规格！');
            return false;
        }

        if ($('#picked').val() == 1 && $('#since_address .checked').length < 1){
            $.alert('error','请选择提货地址！');
            return false;
        }

        if($('#stock').val() < 1) {
            $.alert('error','暂无库存！');
            return false;
        }

        if ($('#picked').val() == 1) {
            var since_id = $('#since_address .checked').data('value');
        }else{
            var since_id = 0;
        }
        $.ajax({
            url: "{BEESCRM::U('base/store/addtocart',array('store_id'=>$storeId,'origin'=>$origin))}",
            type:"POST",
            dataType:"json",
            data: {
                goods_id: $(this).data('id'),
                goods_spec_id:$('#goods_spec_id').val(),
                goods_num:$('#buy-num').val(),
                type:$('#buy_type').val(),
                since_id:since_id
            },
            success:function (res) {
                if(res.status = "S") {
                    $('#shopping').removeClass('up');
                    $('#cover').fadeOut(500);
                    if($('#buy_type').val() == 'buy') {
                        location.href = res.confirm_url;
                    } else {
                        $.alert("success",res.message);
                    }
                }
            }
        });
    });

    $(document).on('click','#addToCollection',function(){
        $.getAjax({
            url: '/base/store/movetocollection/store_id/{BEESCRM:$storeId}',
            method: 'POST',
            data: {'goods_id': "{BEESCRM:$data.goods_id}"}
        }, true, function (data) {
            if(data.flag == 1){
                //$('#addToCollection').css('color','#fe9a33');
                $('#addToCollection').addClass('collect');
                $.alert('success',data.message)
            }else {
                //$('#addToCollection').css('color','gray');
                $('#addToCollection').removeClass('collect');
                $.alert('success',data.message)
            }
        });
    });
</script>